package com.togglz.example.togglzexample;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.togglz.core.Feature;
import org.togglz.core.repository.FeatureState;
import org.togglz.core.repository.StateRepository;

public class RedisStateRepository implements StateRepository {

    @Autowired
    private RedisTemplate<String, FeatureState> stringRedisTemplate;

    @Override
    public FeatureState getFeatureState(Feature feature) {
        return stringRedisTemplate.opsForValue().get(feature.name());
    }

    @Override
    public void setFeatureState(FeatureState featureState) {
        stringRedisTemplate.opsForValue().set(featureState.getFeature().name(), featureState);
    }
}
